use mlua::{UserData, UserDataMethods};
use super::model_request::HttpRequest;
use super::function::http_do;

#[derive(serde::Deserialize,Clone,serde::Serialize,Default)]
pub struct HttpModule {}

impl UserData for HttpModule {
    fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) {
        methods.add_method("new_request",|_,_http,()|{
            let request = HttpRequest::default();
            Ok(request)
        });
        methods.add_async_method ("send",|lua,_http,m:HttpRequest|async move{
            let res = http_do(lua,m).await;
            Ok(res)
        });
    }
}